#include<stdio.h>

#define MAX_NUM 30000

int maxArea(int* height, int heightSize)
{
    int left = 0, right = heightSize-1;
    int res = 0;
    while(left<=right)
    {
        if(height[left]<= height[right])
        {
            int h = height[left];
            res = res > h*(right-left) ? res : h*(right-left);
            left++;
        }
        else
        {
            int h = height[right];
            res = res > h*(right-left) ? res : h*(right-left);
            right--;
        }
    }
    return res;
}
/*
int maxArea(int* height, int heightSize)
{
    int res[MAX_NUM]={0};
    for(int i = 1;i<heightSize;++i)
    {
        int cmax = 0;
        for(int j=i-1;j>=0;--j)
        {
            int tmp = (height[i]<height[j] ? height[i] : height[j] ) * (i-j);
            cmax = tmp>cmax ? tmp : cmax;
        }
        res[i] = cmax>res[i-1] ? cmax:res[i-1];
    }
    return res[heightSize-1];
}
*/

int main(int argc, char const *argv[])
{
    freopen("./medium/test.txt","r",stdin);
    int N; scanf("%d",&N);
    int height[MAX_NUM]={0}; for(int i=0;i<N;++i)scanf("%d",height+i);

    int res = maxArea(height,N);
    printf("%d\n",res);
    return 0;
}